﻿namespace WCFMINERP.COM
{
	#region

	using System;
	using System.Linq;
	using System.Runtime.InteropServices;
	using System.Text;


	#endregion

	public class IniFile {
		public static IniFile Ini;
		public static string AppPath;
		public static string ReportPath;
		public static string ReportFilePath;
		public static string VoiPath;
		private static bool _autoOrderOnceOrder;
		private static int[] _zgProCatId;
		public string Path;
        
		static IniFile() {
			string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");
			Ini = new IniFile(path);
			
			AppPath = AppDomain.CurrentDomain.BaseDirectory;
			ReportPath = AppPath + "Reports";
			ReportFilePath = AppPath + "报表文件";
			VoiPath = AppPath + "Voi";
			
			
		}
		public IniFile(string inipath) {
			Path = inipath;
		}

		////声明读写INI文件的API函数 
		[DllImport("kernel32")]
		private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
		[DllImport("kernel32")]
		private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
		//写INI文件
		public void IniWriteValue(string Section, string Key, string Value) {
			WritePrivateProfileString(Section, Key, Value, Path);
		}

		//读取INI文件指定
      
		public string IniReadValue(string Section, string Key, string defVal = "") {
			StringBuilder temp = new StringBuilder(1000);
			int i = GetPrivateProfileString(Section, Key, "", temp, 1000, Path);
			if (temp.Length == 0) {
				IniWriteValue(Section, Key, defVal);
				return defVal;
			}
			return temp.ToString();
		}
	}
}
